package com.qishen.operation.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qishen.operation.mapper.TbEmployeeMapper;
import com.qishen.operation.service.TbEmoloyeeService;
import com.san.model.common.dtos.PageResponseResult;
import com.san.model.common.dtos.ResponseResult;
import com.san.model.common.enums.AppHttpCodeEnum;
import com.san.model.operation.dtos.TbEmployeeDto;
import com.san.model.operation.pojos.TbEmployee;
import org.springframework.stereotype.Service;

@Service
public class TbEmoloyeeServiceImpl extends ServiceImpl<TbEmployeeMapper, TbEmployee> implements TbEmoloyeeService {

    @Override
    public ResponseResult findByNameAndPage(TbEmployeeDto dto) {
        if(dto==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //分页参数检查
        dto.checkParam();

        //2.安装名称模糊分页查询
        Page page = new Page(dto.getPage(),dto.getSize());
        LambdaQueryWrapper<TbEmployee> lambdaQueryWrapper = new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(dto.getName())){
            lambdaQueryWrapper.like(TbEmployee::getName,dto.getName());
        }
        IPage result = page(page, lambdaQueryWrapper);

        //3.结果封装
        ResponseResult responseResult = new PageResponseResult(dto.getPage(),dto.getSize(),(int)result.getTotal());
        responseResult.setData(result.getRecords());
        return responseResult;
    }
}
